/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tuplegenerator;

import java.text.DecimalFormat;

/**
 *
 *
 */
public class SingleTuple extends Tuple {
    
    private long timestamp = 0;
    private int meterID = 0;
    private double activePower = 0.0;
    
    public static DecimalFormat df = new DecimalFormat("#0.0000");
    public static DecimalFormat df2 = new DecimalFormat("#0.00");
    
    public SingleTuple() {
        
    }
    
    public SingleTuple(int meterId, double apower, double rpower, double v, double i) {
        timestamp = System.currentTimeMillis();
        
        meterID = meterId;
        activePower = apower;
    }

    public static SingleTuple parseTuple(String tuple) {
        String[] parts = tuple.split("[;]");
        if (parts.length >= 3) {
            
            SingleTuple t = new SingleTuple();
            t.setMeterID(Integer.parseInt(parts[1]));
            t.setActivePower(Double.parseDouble(parts[2]));
            
            
            return t;
            
        } else {
            return null;
        }
    }
    
    @Override
    public String toString() {
        return timestamp + ";" + meterID + ";" + df.format(activePower);
    }
    
    /**
     * @return the meterID
     */
    public int getMeterID() {
        return meterID;
    }

    /**
     * @param meterID the meterID to set
     */
    public void setMeterID(int meterID) {
        this.meterID = meterID;
    }

    /**
     * @return the activePower
     */
    public double getActivePower() {
        return activePower;
    }

    /**
     * @param activePower the activePower to set
     */
    public void setActivePower(double activePower) {
        this.activePower = activePower;
    }

    @Override
    public int getKey() {
        return meterID;
    }

	@Override
	public int compareTo(Tuple o) {
		SingleTuple st = (SingleTuple)o;
        if (this.meterID > st.meterID) return 1;
        if (this.meterID < st.meterID) return -1;
        return 0;
	}
    
    
    
    
}
